from threading import local

from django.utils.deprecation import MiddlewareMixin
from django_currentuser.middleware import _set_current_user

from django_starter.contrib.auth.services import get_user

_active = local()


class CurrentUserMiddleware(MiddlewareMixin):

    def process_request(self, request):
        user = get_user(request)
        if user:
            request.user = user